<template>
  <el-form
    ref="ruleFormRef"
    style="max-width: 280px"
    :model="formData"
    status-icon
    label-width="auto"
    class="demo-ruleForm"
  >
    <el-form-item label="用户名" prop="user">
      <el-input v-model="formData.user" type="text" autocomplete="off" />
    </el-form-item>
    <el-form-item label="密码" prop="pase">
      <el-input v-model="formData.pass" type="password" autocomplete="off" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)"> Submit </el-button>
      <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormInstance } from 'element-plus'

import { useRouter } from 'vue-router'
import { login, regist } from '@/utils/login'
const router = useRouter()

const ruleFormRef = ref<FormInstance>()

const formData = reactive({
  user: '',
  pass: '',
})

function submitForm(el: FormInstance | undefined) {
  login(formData)
  router.push({ name: 'home' })
}

function resetForm(el: FormInstance | undefined) {
  regist(formData)
}
</script>

<style scoped>
form {
  padding: 80px;
  justify-self: center;
  align-self: center;
}
</style>
